#ifndef _PID_H_
#define _PID_H_

typedef struct {
    float kp, ki, kd;
    float dynamic_p, dynamic_i, dynamic_d;
    float error, last_error;
    float max_dynamic_i; // 最大的动态I值
    float output, max_output;
    int target;
} PID;

void pid_init(PID *pid, float kp, float ki, float kd, float max_dynamic_i, float max_output, int target);
void pid_set_target(PID *pid, int target);
void pid_set_gain(PID *pid, float kp, float ki, float kd);
void pid_set_dynamic_gain(PID *pid, float dynamic_p, float dynamic_i, float dynamic_d);
void pid_set_max_dynamic_i(PID *pid, float max_dynamic_i);
void pid_set_max_output(PID *pid, float max_output);

float pid_calc(PID *pid, float target, float current_value);

void pid_dynamic_clear(PID *pid);

#endif